package com.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.crm.common.ResVo;
import com.crm.entity.PhotoCategory;
import com.crm.service.PhotoCategoryService;
import com.spring4all.swagger.EnableSwagger2Doc;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@EnableSwagger2Doc
@RequestMapping("/photoCategory")
@Api(tags = "图片类别管理")
public class PhotoCategoryController {

	@Autowired
	private PhotoCategoryService photoCategoryService;

	@GetMapping("/getPhotoCategory")
	@ApiOperation("获取图片分类")
	public ResVo<Object> getPhotoCategory() {
		List<PhotoCategory> message = photoCategoryService.getPhotoCategory();
		return ResVo.success(message);
	}

	@GetMapping("/getPhotosCategory/{pageIndex}")
	@ApiOperation("按条件获取新闻分类")
	public ResVo<Object> getPhotosCategoryBycategory(
			@RequestParam(value = "category", required = false) @ApiParam("分类名") String category,
			@PathVariable("pageIndex") @ApiParam("页码") Integer pageIndex) {
		Page<PhotoCategory> message = photoCategoryService.getPhotosCategoryBycategory(category, pageIndex);
		return ResVo.success(message);
	}

	@PostMapping("/addPhotoCategory")
	@ApiOperation("添加图片类别")
	public ResVo<Object> addPhotoCategory(@RequestBody PhotoCategory photoCategory) {
		photoCategoryService.addPhotoCategory(photoCategory);
		return ResVo.defaultSuccess();
	}

}
